<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="../inc.jsp"></jsp:include>
<%@taglib prefix="wtu" uri="http://ismp.webtoolsutil"%>
</head>
<body>

	<div id="incomeDetail" class="easyui-tabs"
		data-options="fit:true,onSelect : function(title,index) {
					if (index == 1) {
						loadGrid();
					}
				}">
		<div title="基本信息" data-options="closable:false">

			<input type="hidden" name="projectName"
				value="${projectInfo.projectName}" id="projectName" />
			<table border="1" style="width: 100%">
				<tr>
					<td colspan="8" align="center" bgcolor="#999999">项目基本信息</td>
				</tr>
				<tr>
					<td colspan="2" align=left bgcolor="#33FFFF">事业部</td>
					<td colspan="2" align=left>华东华为事业一部</td>
					<td colspan="2" align=left bgcolor="#33FFFF">业务部</td>
					<td colspan="2" align=left>${wtu:getDepartmentNameById(projectInfo.departmentId)}</td>
				</tr>
				<tr>
					<td colspan="2" align=left bgcolor="#33FFFF">项目名称</td>
					<td colspan="2" align=left>${projectInfo.projectName}</td>
					<td colspan="2" align=left bgcolor="#33FFFF">项目类型</td>
					<td colspan="2" align=left>${projectInfo.projectType}</td>
				</tr>
				<tr>
					<td colspan="2" align=left bgcolor="#33FFFF">客户名称</td>
					<td colspan="2" align=left>${projectInfo.defineName}</td>
					<td colspan="2" align=left bgcolor="#33FFFF">项目经理</td>
					<td colspan="2" align=left>${projectInfo.employeeName}</td>
				</tr>
				<tr>
					<td colspan="2" align=left bgcolor="#33FFFF">总收入</td>
					<td colspan="2" align=left></td>
					<td colspan="2" align=left bgcolor="#33FFFF">总成本</td>
					<td colspan="2" align=left></td>
				</tr>
				<tr>
					<td colspan="2" align=left bgcolor="#33FFFF">NOPO</td>
					<td colspan="2" align=left>${row.obj.contractMoney}-${row.obj.billSumMoney }</td>
					<td colspan="2" align=left bgcolor="#33FFFF">回款</td>
					<td colspan="2" align=left>${row.obj.billSumMoney }</td>
				</tr>
				<tr>
					<td colspan="8" align="center" bgcolor="#999999">合同匹配信息</td>
				</tr>
			</table>
			<table id="incomecontract">
			</table>
		</div>
		<div title="投入明细" data-options="closable:false">
			<div class="easyui-panel" style="padding: 0px; background: #fafafa;"
				data-options="fit:true">
				<table id="incomeMonthDetail">
				</table>
			</div>

		</div>
	</div>


	<script type="text/javascript">
		var incomeMonthDetailDatagird;

		var projectName = document.getElementById('projectName').value;
		projectName = projectName.replace(/%/g, "%25");
		projectName = projectName.replace(/\&/g, "%26");
		projectName = projectName.replace(/\+/g, "%2B");

		var getIncomeContractUrl = "${pageContext.request.contextPath}/IncomeController/getIncomeContract?incomeName="
				+ projectName;
		var incomecontractdatagrid;
		$(function() {

			incomecontractdatagrid = $('#incomecontract').datagrid({

				url : getIncomeContractUrl,
				fit : true, //自动大小
				fitColumns : false, //自适应列宽
				idField : 'po',
				showFooter : true,
				nowrap : false,
				toolbar : [ {
					text : '关联合同',
					iconCls : 'icon-add',
					handler : function() {
						RelateContractsFun();
					}
				}, "-", {
					text : '取消关联',
					iconCls : 'icon-remove',
					handler : function() {
						unRelateContractsFun();
					}
				} ],
				columns : [ [ {
					field : 'po',
					title : '合同编号',
					width : '120px',
					checkbox : true
				}, {
					field : 'contractName',
					title : '合同名称',
					width : '280px'
				}, {
					field : 'contractMoney',
					title : '合同金额',
					width : '60px',
					editor : 'text'
				}, {
					field : 'billSumMoney',
					title : '回款金额',
					width : '60px',
					editor : 'text'
				}, {
					field : 'kpMoney',
					title : '开票金额',
					width : '60px',
					editor : 'text'
				} ] ],
				onDblClickCell : function(index, field, value) {
					$(this).datagrid('beginEdit', index);
					var ed = $(this).datagrid('getEditor', {
						index : index,
						field : field
					});
				}

			});
		});

		function loadGrid() {
			incomeMonthDetailDatagird = $('#incomeMonthDetail').datagrid({
				url : "${pageContext.request.contextPath}/income/incomeMonthDetail.json",
				fit : true, //自动大小
				fitColumns : false, //自适应列宽
				idField : 'po',
				singleSelect : true,
				showFooter : true,
				toolbar : [ {
					text : '1月',
					handler : function() {
						queryMonthDetail('1');
					}
				}, "-", {
					text : '2月',
					handler : function() {
						queryMonthDetail('2');
					}
				}, "-", {
					text : '3月',
					handler : function() {
						queryMonthDetail('3');
					}
				}, "-", {
					text : '4月',
					handler : function() {
						queryMonthDetail('4');
					}
				}, "-", {
					text : '5月',
					handler : function() {
						queryMonthDetail('5');
					}
				}, "-", {
					text : '6月',
					handler : function() {
						queryMonthDetail('6');
					}
				}, "-", {
					text : '7月',
					handler : function() {
						queryMonthDetail('7');
					}
				}, "-", {
					text : '8月',
					handler : function() {
						queryMonthDetail('8');
					}
				}, "-", {
					text : '9月',
					handler : function() {
						queryMonthDetail('9');
					}
				}, "-", {
					text : '10月',
					handler : function() {
						queryMonthDetail('10');
					}
				}, "-", {
					text : '11月',
					handler : function() {
						queryMonthDetail('11');
					}
				}, "-", {
					text : '12月',
					handler : function() {
						queryMonthDetail('12');
					}
				} ],
				columns : [ [ {
					field : 'employeeId',
					title : '工号',
					width : '60px'
				}, {
					field : 'employeeName',
					title : '姓名',
					width : '80px'
				}, {
					field : 'startTime',
					title : '开始时间',
					width : '80px'
				}, {
					field : 'endTime',
					title : '结束时间',
					width : '80px'
				}, {
					field : 'incomeDate',
					title : '结算人天',
					width : '60px'
				}, {
					field : 'incomeUp',
					title : '单价',
					width : '60px'
				}, {
					field : 'unitTotal',
					title : '人月单价',
					width : '60px'
				} ] ]
			});
		}

		function queryMonthDetail(month) {
			if (month == 2) {
				incomeMonthDetailDatagird.datagrid({
					url : '${pageContext.request.contextPath}/income/incomeMonthDetail2.json'
				});
			} else {
				incomeMonthDetailDatagird.datagrid({
					url : '${pageContext.request.contextPath}/income/incomeMonthDetail.json'
				});
			}
		}

		//取消合同关联
		function unRelateContractsFun() {

			var selRow = $('#incomecontract').datagrid("getSelections");//返回选中多行  

			if (selRow.length == 0) {
				parent.$.messager.show({
					title : '提示信息',
					msg : '请至少选择一行数据!',

				});
				return false;
			}
			var contractids = [];
			for (var i = 0; i < selRow.length; i++) {
				//获取自定义table 的中的checkbox值  
				var id = selRow[i].po; //OTRECORDID这个是你要在列表中取的单个id   
				contractids.push(id); //然后把单个id循环放到ids的数组中  
			}
			var url = '${pageContext.request.contextPath}/IncomeController/unRelateContracts?contractids='
					+ contractids + '&incomeName=' + projectName;

			if (confirm("确定要取消关联么?")) {
				$.ajax({
					url : url,
					type : 'post',
					dataType : 'json',
					success : function(result) {
						if (result.msg) {
							jQuery.messager.alert("操作结果", result.msg);
						} else {
							jQuery.messager.alert("系统异常，请联系管理员");
						}
						$('#incomecontract').datagrid('reload');
					}
				});
			}

		}

		function RelateContractsFun() {
			var urlstr = '${pageContext.request.contextPath}/IncomeController/preReleatContract?incomeName='
					+ projectName;

			$.modalDialog({
				title : '合同匹配',
				width : '660px',
				height : '450px',
				maximizable : false,
				minimizable : false,
				collapsible : false,
				href : urlstr,
				onBeforeClose : function() {
					$('#incomecontract').datagrid('reload');
				}
			});
		}
	</script>
</body>
</html>
